﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace SaveFileInProgramFiles
{
    public partial class SaveFileInProgramFiles : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string fileName = txtFileName.Text;
            if (string.IsNullOrEmpty(fileName) || string.IsNullOrWhiteSpace(fileName))
            {
                lblMessage.Text = "You have not entered a file name!";
            }
            else
            {
                string path = "C:\\Program Files\\" + fileName;
                try
                {
                    File.CreateText(path);
                }
                catch (Exception ex)
                {
                    lblMessage.Text = ex.Message;
                }

                lblMessage.Text = "File " + Server.HtmlEncode(fileName) + " has been successfully created!";
            }
        }
    }
}